#include "audiologo.h"
#include "customdialog.h"

#include <QVBoxLayout>
#include <QLabel>
#include <QBitmap>
#include <QPainter>
#include <QPixmap>
#include <QMouseEvent>
#include <QDebug>

/**
 * @brief AudioLogo::AudioLogo
 * @param parent
 * 小麒麟logo界面，双击即可打开语音助手界面
 */


AudioLogo::AudioLogo(QWidget* parent) : QDialog(parent) {
    setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    // 设置透明度
    setAttribute(Qt::WA_TranslucentBackground);

    QPixmap pix;
    pix.load(":/icons/images/app.png");
    qDebug() << pix.size();
    resize(pix.size());
    setMask(pix.mask());

    setupUI();
}

void AudioLogo::paintEvent(QPaintEvent* event)
{
    QPainter painter(this);
    QPixmap pix = QPixmap(":/icons/images/app.png");
    QImage image(pix.size(), QImage::Format_ARGB32);
    image.fill(Qt::transparent);

    QPainter imagePainter(&image);
    imagePainter.drawImage(QPoint(0, 0), pix.toImage());
    QPixmap scaledPixmap = QPixmap::fromImage(image).scaled(size(), Qt::KeepAspectRatio);
    // 调整图片尺寸
    painter.drawPixmap(0, 0, scaledPixmap);
}

// 双击小麒麟图标,窗口消失,同时主窗口中继续打开语音助手功能
void AudioLogo::mouseDoubleClickEvent(QMouseEvent* event)
{
    if (event->button() == Qt::LeftButton)
    {
        this->close();
        emit startAssistant();
    }
}

// 手动实现界面随着鼠标的拖动而移动
void AudioLogo::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        lastMousePosition = event->globalPos() - frameGeometry().topLeft();
        event->accept();
    }
}
void AudioLogo::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton)
    {
        move(event->globalPos() - lastMousePosition);
        event->accept();
    }
}

void AudioLogo::setupUI() {

}

AudioLogo::~AudioLogo() {}

